package com.yvon.service.demo.spring.beans.factory.support;

import com.yvon.service.demo.spring.beans.factory.config.SingletonBeanRegistry;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 默认单例bean注册表
 *
 * 定义一个Map用来缓存单例bean
 * 并实现单例bean注册表的注册与获取接口
 *
 * @author Yvon
 * @since 2022-11-24
 */
public class DefaultSingletonBeanRegistry implements SingletonBeanRegistry {
    private Map<String, Object> singletonObjects = new ConcurrentHashMap<>();

    @Override
    public Object getSingleton(String beanName) {
        return singletonObjects.get(beanName);
    }

    @Override
    public void registerSingleton(String beanName, Object singletonObject) {
        singletonObjects.put(beanName, singletonObject);
    }
}
